
import type Viewer from '../Viewer';
import { DragControls } from 'three/examples/jsm/controls/DragControls';
import { TransformControls } from 'three/examples/jsm/controls/TransformControls';
export default class Drag {
    public viewer: Viewer;
    constructor(viewer: Viewer) {
        this.viewer = viewer;
    }

    // 添加拖拽控件
    public initDragControls(objects: any) {
        let that = this;
        // 添加平移控件
        var transformControls = new TransformControls(this.viewer.camera, this.viewer.renderer.domElement);
        this.viewer.scene.add(transformControls);
        // 初始化拖拽控件
        var dragControls = new DragControls(objects, this.viewer.camera, this.viewer.renderer.domElement);
        // 鼠标略过事件
        dragControls.addEventListener('hoveron', function (event) {
            // 让变换控件对象和选中的对象绑定
            transformControls.attach(event.object);
        });
        this.viewer.controls.enabled = false;
        // 开始拖拽
        dragControls.addEventListener('dragstart', function (event) {
            that.viewer.controls.enabled = false;
        });
        // 拖拽结束
        dragControls.addEventListener('dragend', function (event) {
            that.viewer.controls.enabled = true;
        });
    }
}


